package com.nf.health.app.mine.activity;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.adapter.MyIntegrationListAdapter;
import com.nf.health.app.customview.MyListView;
import com.nf.health.app.models.IntegrationVo;
import com.nf.health.app.utils.ActivityUtils;
import com.nf.health.app.utils.PreferenceHelper;
import com.nf.health.app.utils.ViewUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 我的积分
 *
 * @author jiax
 */
public class MyIntegrationActivity extends BaseActivity implements
        OnClickListener {
    @Bind(R.id.interation_listview)//积分任务列表
            MyListView interationListview;


    private MyIntegrationListAdapter myIntegrationListAdapter;

    private TextView tv_next_score;
    private ImageView iv_user_head_icon;
    private TextView tv_integration;
    private ProgressBar home_seekbar;
    private ImageView vp_0;
    private ImageView vp_1;
    private ImageView vp_2;
    private ImageView vp_3;
    private ImageView vp_4;
    private ImageView vp_5;
    private ImageView integration_image;


    List<IntegrationVo> integrationVos;

    private TextView titlebar_right_tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTitleBar(R.layout.titlebar_base);
        setContent(R.layout.activity_my_interation);
        ButterKnife.bind(this);


        ViewUtil.setText(this, R.id.titlebar_title_tv, "我的积分");

        ViewUtil.setText(this, R.id.titlebar_right_tv, "详情");

        titlebar_right_tv = ViewUtil.getView(this, R.id.titlebar_right_tv);

        titlebar_right_tv.setText("详情");

        titlebar_right_tv.setVisibility(View.VISIBLE);


        provider.requestIntergration("intergration_rwb");//积分列表


        //provider.requestMyScore("myscore");//我的积分

        integration_image = ViewUtil.getView(this, R.id.integration_image);
        tv_integration = ViewUtil.getView(this, R.id.tv_integration);
        iv_user_head_icon = ViewUtil.getView(this, R.id.iv_user_head_icon);
//		tv_next_score = ViewUtil.getView(this, R.id.tv_next_score);

        home_seekbar = ViewUtil.getView(this, R.id.home_seekbar);
        home_seekbar.setMax(1500);

        vp_1 = ViewUtil.getView(this, R.id.vp_1);
        vp_2 = ViewUtil.getView(this, R.id.vp_2);
        vp_3 = ViewUtil.getView(this, R.id.vp_3);
        vp_4 = ViewUtil.getView(this, R.id.vp_4);
        vp_5 = ViewUtil.getView(this, R.id.vp_5);
        setViewByGrade();
        initData();

    }

    private void initData() {
        titlebar_right_tv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转详情页
                Bundle bundle = new Bundle();
                bundle.putString("bill", "integration");
                ActivityUtils.showActivity(MyIntegrationActivity.this, BillActivity.class, bundle);

            }
        });

    }

    @Override
    public void handleActionSuccess(String actionName, Object object) {

        if ("intergration_rwb".equals(actionName)) {
            integrationVos = (List<IntegrationVo>) object;
            myIntegrationListAdapter = new MyIntegrationListAdapter(integrationVos,this);
            interationListview.setAdapter(myIntegrationListAdapter);
        }
    }

    private void setViewByGrade(){
        String grade = PreferenceHelper.getString(PreferenceHelper.GRADE,"0");
        String gradeValue = PreferenceHelper.getString(PreferenceHelper.GRADE_VALUE,"0");
        tv_integration.setText("积分:"+ gradeValue +"分");

        if(grade.equals("1")){
            integration_image.setImageResource(R.drawable.lv1);
            iv_user_head_icon.setImageResource(R.drawable.integration_bg2);
        }else if(grade.equals("2")){
            integration_image.setImageResource(R.drawable.lv2);
            iv_user_head_icon.setImageResource(R.drawable.integration_bg2);
        }else if(grade.equals("3")){
            integration_image.setImageResource(R.drawable.lv3);
            iv_user_head_icon.setImageResource(R.drawable.integration_bg2);
        }else if(grade.equals("4")){
            integration_image.setImageResource(R.drawable.lv4);
            iv_user_head_icon.setImageResource(R.drawable.integration_bg2);
        }else if(grade.equals("5")){
            integration_image.setImageResource(R.drawable.lv5);
            iv_user_head_icon.setImageResource(R.drawable.integration_bg2);
        }

        home_seekbar.setProgress(Integer.parseInt(gradeValue));
        switch (Integer.parseInt(grade)) {
            case 1:
                vp_1.setBackgroundResource(R.drawable.ic_grade_11);
                break;
            case 2:
                vp_1.setBackgroundResource(R.drawable.ic_grade_11);
                vp_2.setBackgroundResource(R.drawable.ic_grade_21);
                break;
            case 3:
                vp_1.setBackgroundResource(R.drawable.ic_grade_11);
                vp_2.setBackgroundResource(R.drawable.ic_grade_21);
                vp_3.setBackgroundResource(R.drawable.ic_grade_31);
                break;
            case 4:
                vp_1.setBackgroundResource(R.drawable.ic_grade_11);
                vp_2.setBackgroundResource(R.drawable.ic_grade_21);
                vp_3.setBackgroundResource(R.drawable.ic_grade_31);
                vp_4.setBackgroundResource(R.drawable.ic_grade_41);
                break;
            case 5:
                vp_1.setBackgroundResource(R.drawable.ic_grade_11);
                vp_2.setBackgroundResource(R.drawable.ic_grade_21);
                vp_3.setBackgroundResource(R.drawable.ic_grade_31);
                vp_4.setBackgroundResource(R.drawable.ic_grade_41);
                vp_5.setBackgroundResource(R.drawable.ic_grade_51);
                break;
            default:
                break;
        }
    }
}
